<?php
require('header.php');

if(isset($_REQUEST['title']) && isset($_REQUEST['content'])) {
    $tech_id=$_REQUEST['technology'];
    $title=$_REQUEST['title'];
    $content=$_REQUEST['content'];
    $sql="INSERT INTO reference (title,content,tech_id) VALUES('$title','$content','$tech_id') ";
    mysql_query($sql) or die("Can not add to database");
    $add_ref=1;
}

$sql="SELECT * FROM technology";
$tech=mysql_query($sql) or die('Could not load technologies from DB.');
?>
	<h1>Add a new Reference</h1>
	<hr>

    <?php
    if(isset($add_ref)) {
        echo '<div class="alert alert">';
    }
    ?>
    
    
	<form method="post" action="<?=$_SERVER['PHP_SELF'];?>">
		<label>Title</label>
		<input type="text" name="title" placeholder="Reference Title" class="span4">
		<label>Technology</label>
		<select name="technology" class="span4">

		<?php
		while($row=mysql_fetch_assoc($tech)) {
			echo '<option value="'.$row['tech_id'].'">'.$row['technology'].'</option>';
		}
		?>
		</select>
		<label>Content</label>
        <textarea name="content" class="span8" rows="15"></textarea>
        <hr>
        <input type="submit" name="submit" value="Submit" class="btn-primary btn-large">
    </form>

    </div> <!-- /container -->

    <!-- Le javascript
    ================================================== -->
    <!-- Placed at the end of the document so the pages load faster -->
    <script src="assets/js/jquery.js"></script>
    <script src="assets/js/bootstrap-transition.js"></script>
    <script src="assets/js/bootstrap-alert.js"></script>
    <script src="assets/js/bootstrap-modal.js"></script>
    <script src="assets/js/bootstrap-dropdown.js"></script>
    <script src="assets/js/bootstrap-scrollspy.js"></script>
    <script src="assets/js/bootstrap-tab.js"></script>
    <script src="assets/js/bootstrap-tooltip.js"></script>
    <script src="assets/js/bootstrap-popover.js"></script>
    <script src="assets/js/bootstrap-button.js"></script>
    <script src="assets/js/bootstrap-collapse.js"></script>
    <script src="assets/js/bootstrap-carousel.js"></script>
    <script src="assets/js/bootstrap-typeahead.js"></script>
    <script src="assets/tinymce/jscripts/tiny_mce/tiny_mce.js"></script>
    <script type="text/javascript" >
		tinyMCE.init({
        mode : "textareas",
        theme : "simple"   //(n.b. no trailing comma, this will be critical as you experiment later)
		});
	</script >
  </body>
</html>
